package com.example.administrator.waitan.find.art;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LayoutAnimationController;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.ListView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.example.administrator.waitan.R;
import com.example.administrator.waitan.base.BaseActivity;
import com.example.administrator.waitan.find.art.ArtContentActivity.WomanContentActivity;
import com.example.administrator.waitan.tools.GsonRequest;
import com.example.administrator.waitan.tools.VolleySingleton;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/12.
 */
public class ArtActivity extends BaseActivity {
    private Toolbar mToolbar;
    private RequestQueue queue;
    private ArrayList<WomanListInfo> womanListInfos;
    private ListView womenListView;
    private List<Integer> Datas;
    private ListView jokeListview;
    private WomanBaseAdapter womenAdapter;
    private String womenUrl = "http://a.17173.com/api/photos/list?sections=8&unread=false&uuid=000000000000000&pageSize=10&pageIndex=0&maxPublicDate=0&platCode=ANDROID";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final ArtProgressDialog dialog = new ArtProgressDialog(this,"页面加载中......",R.anim.activity_in);
        dialog.show();
        setContentView(R.layout.activity_art);
        womenListView = (ListView) findViewById(R.id.lv_art_woman);
        GsonRequest<WomanBeans> gsonRequest = new GsonRequest<WomanBeans>(womenUrl, WomanBeans.class, new Response.Listener<WomanBeans>() {
            @Override
            public void onResponse(final WomanBeans response) {
                womenAdapter = new WomanBaseAdapter(ArtActivity.this, response.getData().getList());
                womenListView.setAdapter(womenAdapter);
                womenListView.setLayoutAnimation(getListAnim());
                dialog.dismiss();
                womenListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        Intent intent = new Intent(ArtActivity.this, WomanContentActivity.class);
                        intent.putExtra("title", response.getData().getList().get(i).getTitle());
                        intent.putExtra("ID", response.getData().getList().get(i).getID());
                        startActivity(intent);
                    }
                });
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        VolleySingleton.getInstance()._addRequest(gsonRequest);
    }
    private LayoutAnimationController getListAnim() {
        AnimationSet set = new AnimationSet(true);
        Animation animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setDuration(600);
        set.addAnimation(animation);

        animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
                Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
                -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
        animation.setDuration(600);//设置动画时间
        set.addAnimation(animation);
        LayoutAnimationController controller = new LayoutAnimationController(
                set, 0.5f);
        return controller;
    }
}
